package mo.offer_version2;

public class L39 {

    public int majorityElement(int[] nums) {
        int x = nums[0], votes = 1;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] == x) {
                votes++;
            } else {
                if (votes == 0) {
                    x = nums[i];
                } else {
                    votes--;
                }
            }
        }
        return x;
    }

}
